/*! \file IndexBufferImpl.cpp
 *	\brief 
 *
 *	created:	2010/12/12
 *	created:	12:12:2010   23:43
 *	filename: 	C:\src\tactics-engine\libs\gd_dx11\IndexBufferImpl.cpp
 *	file path:	C:\src\tactics-engine\libs\gd_dx11
 *	file base:	IndexBufferImpl
 *	file ext:	cpp
 *	author:		Vitalii Trubchaninov
 *				venngraydog@gmail.com
 */
#include "gd_dx11/stdafx.h"
#include "gd_dx11/IndexBufferImpl.h"

#include "gd_dx11/DeviceContext.h"

namespace tt{
namespace gd_dx11{

IndexBufferImpl::IndexBufferImpl()
{

}

IndexBufferImpl::~IndexBufferImpl()
{

}

tt::Result IndexBufferImpl::Create( Device* device, UInt count )
{
	UInt dataSize = sizeof(UInt) * count;
	return doCreate(device, D3D11_BIND_INDEX_BUFFER, dataSize);
}

void IndexBufferImpl::onApply( gd::DeviceContext* deviceContext )
{
	lock(deviceContext);
	UInt* ip = reinterpret_cast<UInt*>( data() );
	ip[0] = 0;
	ip[1] = 1;
	ip[2] = 2;
	unlock(deviceContext);

	DeviceContext* dx11DeviceContext = getDx11Context(deviceContext);
	dx11DeviceContext->d3dContext()->IASetIndexBuffer(buffer().get(), DXGI_FORMAT_R32_UINT, 0);
	dx11DeviceContext->d3dContext()->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
}

} //namespace gd_dx11
} //namespace tt